import uuid
from datetime import datetime

from django.db import models

# Create your models here.


class City(models.Model):
    name = models.CharField(max_length=100)

    class Meta:
        db_table  = 'tb_city'

def avatar_upload_path(instance, filename):
    print(instance)
    ext = filename.split('.')[-1]
    filename = f'{uuid.uuid4()}.{ext}'
    now = datetime.now()
    return f'avatars/{now.year}/{now.month}/{now.day}/{filename}'

class Student(models.Model):
    GENDERChoices = (
        (0, '男'),
        (1, '女'),
    )

    name = models.CharField(max_length=100)
    gender = models.IntegerField(choices=GENDERChoices,default=0)
    avatar = models.ImageField(upload_to=avatar_upload_path, null=True, blank=True)
    hobbies = models.CharField(max_length=100)
    city = models.ForeignKey(City, on_delete=models.CASCADE)
    phone = models.CharField(max_length=11)
    create_time = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'tb_student'